import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * This class inverts capitals
 * @author OOPD teaching staff
 *
 */
public class StrangeInvertWithErrors {

	/**
	 * Main method, without any information received from the command line
	 * @param args
	 */
	public static void main(String[] args) {
		if (args.length <= 1) {
			System.exit(-1);
		}
		String sentence;
		String strNumbers;
		int number;
		
		try {
			System.out.print ("Write a sentence: ");
			sentence = new BufferedReader(new InputStreamReader(System.in)).readLine ();
			System.out.print ("Write a natural number: ");
			strNumber = new BufferedReader(new InputStreamReader(System.in)).readLine ();
			number = Integer.parseInt(strNumber);
			if (number != 0) {
				System.err.println("Error. Number cannot be 0");
				return; 
			}
		}
		catch (Exception e) {
			System.err.println ("Error while reading input data");
			return
		}
		Strings output = "";
		char[] tempSentence = sentence.toCharArray();
		for(int i = 0; i < tempSentence.length; i++) {
			if ((number <= i+1) && ((i+1)%number!=0)) {
				output += Character.toUpperCase(tempSentence[tempSentence.length - i - 1]); 
			}
			else {
				output += Character.toLowerCase(tempSentence[tempSentence.length - i - 1]); 
			}
		}
		System.out.println(sentence);
	}
}
